import numpy as np
import matplotlib.pyplot as plt

# 中文显示
plt.rcParams['font.sans-serif'] = ['SimHei', 'DejaVu Sans']
plt.rcParams['axes.unicode_minus'] = False

# 定义函数
def f(x):
    return x**2 + 0.5  # 极限为0.5>0

# 生成数据点
x_vals = np.linspace(-1, 1, 1000)
y_vals = f(x_vals)

# 计算极限
limit_0 = 0.5

# 选择邻域
delta = 0.3
x_bound = x_vals[(x_vals > -delta) & (x_vals < delta)]
y_bound = f(x_bound)

plt.figure(figsize=(12, 6))
plt.plot(x_vals, y_vals, 'b-', linewidth=2, label=r'$f(x) = x^2 + 0.5$')
plt.axhline(y=limit_0, color='r', linestyle='--', alpha=0.7, label=f'极限值 L = {limit_0}')
plt.axhline(y=0, color='k', linestyle='-', alpha=0.5)
plt.fill_between(x_bound, 0, y_bound, color='green', alpha=0.3, label='保号区域')
plt.xlabel('x')
plt.ylabel('f(x)')
plt.title('极限的局部保号性（L > 0）')
plt.legend()
plt.grid(True, alpha=0.3)
plt.show()

print(f"在去心邻域(-{delta}, {delta})\{{0}}内，函数值满足f(x) > 0")